//
//  classView.m
//  GC_OC
//
//  Created by 叶建辉 on 2022/7/13.
//

#import "classView.h"

@interface ejclassCell : UITableViewCell

@property(nonatomic,strong)NSString *resDic;

@property(nonatomic,assign)NSInteger selectnum;

@end

@interface ejclassCell ()

@property(nonatomic,strong)UILabel *nameLab;

@end

@implementation ejclassCell

-(UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [UILabel new];
        _nameLab.textColor = [UIColor colorWithWhite:.35 alpha:1];
        _nameLab.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLab;
}

-(void)setSelectnum:(NSInteger)superIndex{
    _selectnum = superIndex;
    [self setNeedsLayout];
}

-(void)setResDic:(NSString *)resDic{
    _resDic = resDic;
    _nameLab.text = _resDic;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.nameLab];
        _selectnum = 0;
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
//    HEIGHTDiv*.035+WIDTHDiv*.035
    
    _nameLab.frame = CGRectMake(self.zf_height*.5, 0, self.zf_width-self.zf_height*.9, self.zf_height);
    _nameLab.font = [UIFont systemFontOfSize:_nameLab.zf_height*.35];
    if (_selectnum == self.tag) {
        _nameLab.textColor = [UIColor colorWithHex:@"#32C5FF"];
    }else{
        _nameLab.textColor = [UIColor colorWithWhite:.35 alpha:1];
    }
}

@end


@interface yjclassCell : UITableViewCell

@property(nonatomic,strong)NSString *resDic;

@property(nonatomic,assign)NSInteger selectnum;

@end

@interface yjclassCell ()

@property(nonatomic,strong)UILabel *nameLab;

@property(nonatomic,strong)UIImageView *arrowImg;


@end

@implementation yjclassCell

-(UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [UILabel new];
        _nameLab.textColor = [UIColor colorWithWhite:.35 alpha:1];
        _nameLab.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLab;
}


-(UIImageView *)arrowImg{
    if (!_arrowImg) {
        _arrowImg = [UIImageView new];
        _arrowImg.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
        _arrowImg.hidden = YES;
    }
    return _arrowImg;
}

-(void)setSelectnum:(NSInteger)superIndex{
    _selectnum = superIndex;
    [self setNeedsLayout];
}

-(void)setResDic:(NSString *)resDic{
    _resDic = resDic;
    _nameLab.text = _resDic;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.nameLab];
        [self addSubview:self.arrowImg];
        _selectnum = 0;
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
//    HEIGHTDiv*.035+WIDTHDiv*.035
    _arrowImg.frame = CGRectMake(self.zf_height*.24, self.zf_height*.25, self.zf_height*.05, self.zf_height*.5);
    
    
    _nameLab.frame = CGRectMake(self.zf_height*.5, 0, self.zf_width-self.zf_height*.9, self.zf_height);
    _nameLab.font = [UIFont systemFontOfSize:_nameLab.zf_height*.35];
    
    if (_selectnum == self.tag) {
        _arrowImg.hidden = NO;
        _nameLab.textColor = [UIColor colorWithHex:@"#32C5FF"];
        self.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
    }else{
        _arrowImg.hidden = YES;
        _nameLab.textColor = [UIColor colorWithWhite:.35 alpha:1];
        self.backgroundColor = [UIColor colorWithWhite:.95 alpha:1];
    }
    
}

@end

@interface classView ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UIView *bgv;
@property(nonatomic,strong)UIButton *bgb;
@end

@implementation classView

-(void)setYjdatas:(NSMutableArray *)yjdatas{
    _yjdatas = yjdatas;
    [_yjtableView reloadData];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView == _yjtableView) {
        return _yjdatas.count;
    }
    return _ejdatas.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return .0001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return .0001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _yjtableView) {
        _yjselectNum = indexPath.section;
        [_yjtableView reloadData];
        
        if ([self.delegate respondsToSelector:@selector(yjClickOnTheIndexPathRow:)]) {
            [self.delegate yjClickOnTheIndexPathRow:indexPath.section];
        }
        
    }else{
        _ejselectNum = indexPath.section;
        [_ejtableView reloadData];
        
        if ([self.delegate respondsToSelector:@selector(ejClickOnTheIndexPathRow:)]) {
            [self.delegate ejClickOnTheIndexPathRow:indexPath.section];
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (HEIGHTDiv*.035+WIDTHDiv*.035);
}

static NSString *CellIdentifier = @"CELL";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == _yjtableView) {
        yjclassCell *cell = [[yjclassCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.backgroundColor = [UIColor whiteColor];
        cell.tag = indexPath.section;
        cell.selectnum = _yjselectNum;
        cell.resDic = _yjdatas[indexPath.section];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
    ejclassCell *cell = [[ejclassCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.backgroundColor = [UIColor whiteColor];
    cell.tag = indexPath.section;
    cell.selectnum = _ejselectNum;
    cell.resDic = _ejdatas[indexPath.section];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    _tableView.contentSize = CGSizeMake(WIDTHDiv, (HEIGHTDiv*.035+WIDTHDiv*.035)*(_datas.count+3));
}

-(UITableView *)yjtableView{
    if (!_yjtableView) {
        _yjtableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _yjtableView.backgroundColor = [UIColor colorWithWhite:.95 alpha:1];
        _yjtableView.delegate = self;
        _yjtableView.dataSource = self;
        _yjtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _yjtableView;
}

-(UITableView *)ejtableView{
    if (!_ejtableView) {
        _ejtableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _ejtableView.backgroundColor = [UIColor whiteColor];
        _ejtableView.delegate = self;
        _ejtableView.dataSource = self;
        _ejtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _ejtableView;
}

-(UIView *)bgv{
    if (!_bgv) {
        _bgv = [UIView new];
        _bgv.backgroundColor = [UIColor clearColor];
    }
    return _bgv;
}

-(UIButton *)bgb{
    if (!_bgb) {
        _bgb = [UIButton new];
        [_bgb addTarget:self action:@selector(bgbClik) forControlEvents:UIControlEventTouchUpInside];
        _bgb.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
    }
    return _bgb;
}

-(void)bgbClik{
    if ([self.delegate respondsToSelector:@selector(hideSelf)]) {
        [self.delegate hideSelf];
    }
    self.hidden = YES;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _bgb.frame = CGRectMake(0, 0, self.zf_width, self.zf_height);
    _bgv.frame = CGRectMake(0, -WIDTHDiv*.08, WIDTHDiv, HEIGHTDiv*.4+WIDTHDiv*.08);
    _bgv.layer.cornerRadius = WIDTHDiv*.04;
    _bgv.layer.masksToBounds = YES;
    
    _yjtableView.frame = CGRectMake(0,WIDTHDiv*.08, WIDTHDiv/2, HEIGHTDiv*.4);
    _ejtableView.frame = CGRectMake(WIDTHDiv/2, WIDTHDiv*.08, WIDTHDiv/2, HEIGHTDiv*.4);
    
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _yjdatas = [NSMutableArray array];
        _ejdatas = [NSMutableArray array];
        [self addSubview:self.bgb];
        [self addSubview:self.bgv];
        [_bgv addSubview:self.yjtableView];
        [_bgv addSubview:self.ejtableView];
        _yjselectNum = 0;
        _ejselectNum = 0;
    }
    return self;
}

@end
